#include <bits/stdc++.h>
using namespace std;

const int N = 10;
int card[N];
bool check(int n)
{
    while (n != 0)
    {
        int mod = n % 10;
        if (card[mod] == 0)
            return false;
        card[mod]--;
        n /= 10;
    }
    return true;
}

int main()
{
    for (int i = 0; i < 10; i++)
        card[i] = 2021;

    for (int i = 1;; i++)
    {
        if (!check(i))
        {
            cout << i - 1 << endl;
            break;
        }
    }
    return 0;
}